#! /usr/bin/python
# -*- coding: utf-8 -*-
import elixir
from elixir import *
import hashlib,base64

metadata.bind = "sqlite:///:memory:"

class DRouter(Entity):
 id = Field (Integer, primary_key=True)
 datos = Field (LargeBinary(256))
 relacion = ManyToOne('Relacion')
 date = Field (DateTime)
 def __repr__(self):
  return "hola"
         

class DRelacion(Entity):
  id = Field(Integer, primary_key=True)
  ip = Field(String(40))
  routers = OneToMany('Router')
  def __repr__(self):
   return "Machine <"+str(self.id)+"> from ip: "+ self.ip


class DCredential(Entity):
  user = Field(String(40))
  passwd = Field(String(40))
  def getMd5(self):
   return hashlib.md5(self.user+":"+self.passwd).hexdigest()

  def getBase64(self):
   return base64.b64encode(self.user+":"+self.passwd)

  def getSha1(self):
   return hashlib.sha1(self.user+":"+self.passwd).hexdigest()

  def getSha512(self):
   return hashlib.sha512(self.user+":"+self.passwd).hexdigest()
  
  def getPassBase64(self):
   return base64.b64encode(self.passwd)
  
  def getUserBase64(self):
   return base64.b64encode(self.user)
 